#include "HashTable.h"

namespace wk
{

    template <class K, class V, class HashKey = HashFunc<K>>
    class unordered_map
    {
        struct MapOfKey
        {
            const K &operator()(const std::pair<const K, V> &kv)
            {
                return kv.first;
            }
        };

        using iterator = typename hash_bucket::HashTable<K, std::pair<const K, V>, HashKey, MapOfKey>::Iterator;
        using const_iterator = typename hash_bucket::HashTable<K, std::pair<const K, V>, HashKey, MapOfKey>::ConstIterator;

    public:
        std::pair<iterator, bool> insert(const std::pair<K, V> &kv)
        {
            return unordered_map.Insert(kv);
        }

        bool erase(const K &kv)
        {
            return unordered_map.Erase(kv);
        }

        iterator find(const K &kv)
        {
            return unordered_map.Find(kv);
        }

        iterator begin()
        {
            return unordered_map.Begin();
        }
        iterator end()
        {
            return unordered_map.End();
        }
        const_iterator begin() const
        {
            return unordered_map.Begin();
        }
        const_iterator end() const
        {
            return unordered_map.End();
        }

        V &operator[](const K &key)
        {
            std::pair<iterator, bool> ret = insert({key, {}});
            return ret.first->second;
        }

    private:
        hash_bucket::HashTable<K, std::pair<const K, V>, HashKey, MapOfKey> unordered_map;
    };
}